#!/usr/bin/python

#Copyright (C) Nial Peters 2012
#
#This file is part of AvoScan.
#
#AvoScan is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#AvoScan is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with AvoScan.  If not, see <http://www.gnu.org/licenses/>.


import wx
import sys
import os.path
import cPickle
import matplotlib
matplotlib.use('wxAgg') #bad things happen if you don't use the wxAgg backend

import ica
from ica.gui import FileChooser, PlotManager, ControlWindow


#TODO list:
# create getters and setters for processed scan class
# sort out the update order of all the plots - it is a mess at the moment
# optimise redrawing to make it faster.
# pull processing functions out of classes to make them easier to test/debug
# 
        
if __name__ == '__main__':
    
    if len(sys.argv)>=2 and sys.argv[1] == "test":
        import doctest
        doctest.testmod(ica.gui)
        doctest.testmod(ica.ica_calc)
        sys.exit()
        
    filename = None    
    if len(sys.argv) >=2:
        if sys.argv[1].endswith(".scans"):
            filename = sys.argv[1]
            with open(filename, "rb") as ifp:
                scans = cPickle.load(ifp)
            app = wx.PySimpleApp()
            p = PlotManager(scans)    
            ctrl_win = ControlWindow(p, os.path.basename(filename)+" - ICA Inspect")
            p.show()
            app.MainLoop()
            sys.exit()

        else:
            filename = sys.argv[1]

    app = wx.PySimpleApp()

    f = FileChooser(filename)
    f.CenterOnScreen()
    f.Show()
    app.MainLoop()

